<?php

use Hyperf\Database\Schema\Schema;
use Hyperf\Database\Schema\Blueprint;
use Hyperf\Database\Migrations\Migration;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('commerce_settlement', function (Blueprint $table) {
            $table->comment('商户结算');
            $table->unsignedBigInteger('id')->comment('结算单号');
            $table->unsignedBigInteger('merchant_id')->unsigned()->comment('商户ID');
            $table->integer('order_count')->default(0)->comment('订单数量');
            $table->decimal('total_revenue', 15, 2)->default(0.00)->comment('销售额');
            $table->decimal('settlement_amount', 15, 2)->default(0.00)->comment('应结算金额');
            $table->decimal('paid_amount', 15, 2)->default(0.00)->comment('已结算金额');
            $table->unsignedTinyInteger('settlement_status')->default(1)->comment('结算状态：1-待结算，2-已结算');
            $table->date('settlement_date')->nullable()->comment('结算日期');
            $table->unsignedTinyInteger('payment_method')->comment('付款方式1-银行转账,2-微信支付,3-支付宝支付,4-现金,5-其他付款方式');
            $table->text('remark')->nullable()->comment('备注');
            $table->primary('id');
            $table->index('merchant_id', 'idx_merchant_id');
            $table->index('settlement_status', 'idx_settlement_status');
            $table->index('settlement_date', 'idx_settlement_date');
            $table->timestamps();
            $table->softDeletes();
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('commerce_settlement');
    }
};